﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using SurfaceAreaPresenter;
using SurfaceAreaInfrastructure;

namespace WPFView
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window, ISurfaceAreaView
    {
        public MainWindow()
        {
            InitializeComponent();
            Presenter presenter = new Presenter(this, new HTMLLogger());
        }

        private System.Windows.Visibility convertBoolToVisibility(bool value)
        {
            BooleanToVisibilityConverter converter = new BooleanToVisibilityConverter();
            return (System.Windows.Visibility)converter.Convert(value, null, null, null);
        }

        public bool edgeLabelVisible
        {
            set
            {
                edgeLabel.Visibility = convertBoolToVisibility(value);
            }
        }

        public bool radiusLabelVisible
        {
            set
            {
                radiusLabel.Visibility = convertBoolToVisibility(value);
            }
        }

        public bool directionLabelVisible
        {
            set
            {
                directionLabel.Visibility = convertBoolToVisibility(value);
            }
        }

        public bool edgeTextFieldVisible
        {
            set
            {
                edgeTextBox.Visibility = convertBoolToVisibility(value);
            }
        }

        public bool radiusTextFieldVisible
        {
            set
            {
                radiusTextBox.Visibility = convertBoolToVisibility(value);
            }
        }

        public bool directionTextFieldVisible
        {
            set
            {
                directionTextBox.Visibility = convertBoolToVisibility(value);
            }
        }

        public bool resultButtonVisible
        {
            set
            {
                resultButton.Visibility = convertBoolToVisibility(value);
            }
        }

        public bool resultTextFieldVisible
        {
            set
            {
                resultTextBox.Visibility = convertBoolToVisibility(value);
            }
        }

        public bool errorLabelVisible
        {
            set
            {
                errorLabel.Visibility = convertBoolToVisibility(value);
            }
        }

        public string resultField
        {
            get
            {
                return resultTextBox.Text;
            }
            set
            {
                resultTextBox.Text = value;
            }
        }

        public string edgeValue
        {
            get
            {
                return edgeTextBox.Text;
            }
        }

        public string radiusValue
        {
            get
            {
                return radiusTextBox.Text;
            }
        }

        public string directionValue
        {
            get
            {
                return directionTextBox.Text;
            }
        }

        public string errorValue
        {
            set
            {
                errorLabel.Content = value;
            }
        }

        public string logText
        {
            get
            {
                return logTextBlock.Text;
            }
            set
            {
                logTextBlock.Text = value;
            }
        }

        public bool logRichTextBoxVisible
        {
            set
            {
                logTextBlock.Visibility = convertBoolToVisibility(value);
            }
        }

        public event Action cubeButtonPressed;
        public event Action coneButtonPressed;
        public event Action cylinderButtonPressed;
        public event Action sphereButtonPressed;
        public event Action calculateButtonPressed;
        public event Action readLogButtonPressed;
        public event Action<bool> loggerStateChanged;

        private void cubeButton_Click(object sender, RoutedEventArgs e)
        {
            cubeButtonPressed();
        }

        private void coneButton_Click(object sender, RoutedEventArgs e)
        {
            coneButtonPressed();
        }

        private void cylinderButton_Click(object sender, RoutedEventArgs e)
        {
            cylinderButtonPressed();
        }

        private void sphereButton_Click(object sender, RoutedEventArgs e)
        {
            sphereButtonPressed();
        }

        private void readLogButton_Click(object sender, RoutedEventArgs e)
        {
            readLogButtonPressed();
        }

        private void calculateButton_Click(object sender, RoutedEventArgs e)
        {
            calculateButtonPressed();
        }

        private void fileLoggerRadioButton_Checked(object sender, RoutedEventArgs e)
        {
            if (sender is RadioButton)
            {
                RadioButton loggerButton = (RadioButton)sender;
                if (loggerStateChanged != null)
                {
                    loggerStateChanged(loggerButton.IsChecked.Value);
                }
            }
        }

        public ILogger getFileLogger()
        {
            return new FileLogger();
        }

        public ILogger getHTMLLogger()
        {
            return new HTMLLogger();
        }
    }
}
